﻿@using Website.Models
@{
    IEnumerable<Category> categories = ViewBag.Categories as IEnumerable<Category>;
    int indexFemale = 1;
    int indexMale = 1;
    bool isUpdate = ViewBag.CurrentCategoryID != null;
    int categoryID = isUpdate ? (int)(ViewBag.CurrentCategoryID) : -1;
}
<select id="CategoryID" name="CategoryID">
    <option>1. Sản Phẩm Nữ</option>
    @foreach (Category c in categories.Where(c => !c.Gender))
    {
        if (isUpdate && categoryID == c.CategoryID)
        {
            <option value="@c.CategoryID" selected="selected">1.@indexFemale. @c.CategoryName</option>
        }
        else
        {
            <option value="@c.CategoryID">1.@indexFemale. @c.CategoryName</option>
        }
        foreach (Category sub in c.SubCategories)
        {
            if(isUpdate && sub.CategoryID == categoryID)
            {
                <option value="@sub.CategoryID" selected="selected">+ @sub.CategoryName</option>
            }
            else
            {
                <option value="@sub.CategoryID">+ @sub.CategoryName</option>
            }

        }
        indexFemale++;
    }
    <option>2. Sản Phẩm Nam</option>
    @foreach (Category c in categories.Where(c => c.Gender))
    {
        if(isUpdate && c.CategoryID == categoryID)
        {
            <option value="@c.CategoryID" selected="selected">2.@indexMale. @c.CategoryName</option>
        }
        else
        {
            <option value="@c.CategoryID">2.@indexMale. @c.CategoryName</option>
        }
        foreach (Category sub in c.SubCategories)
        {
            if(isUpdate && sub.CategoryID == categoryID)
            {
                <option value="@sub.CategoryID" selected="selected">+ @sub.CategoryName</option>    
            }
            else
            {
                <option value="@sub.CategoryID">+ @sub.CategoryName</option>
            }
        }
        indexMale++;
    }
</select>